<template>
  <div id="main" style="width: 100vw; height: 100vh-60px"></div>
</template>

<script>
export default {
  mounted() {
    var chartDom = document.getElementById("main");
    var myChart = this.$echarts.init(chartDom);
    var option;

    setTimeout(function () {
      option = {
        legend: {},
        tooltip: {
          trigger: "axis",
          showContent: true, // Set to true to display tooltip content
        },
        dataset: {
          source: [
            ["部门1", "2012", "2013", "2014", "2015", "2016", "2017"],
            ["部门2", 56.5, 82.1, 88.7, 70.1, 53.4, 85.1],
            ["部门3", 60, 70, 40, 80, 50, 70],
            ["部门4", 80, 62.2, 69.5, 90, 45.2, 32.5],
            ["部门5", 25.2, 20, 41.2, 5, 33.9, 100],
          ],
        },
        xAxis: { type: "category" },
        yAxis: { gridIndex: 0 },
        grid: { top: "55%" },
        series: [
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            emphasis: { focus: "series" },
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            emphasis: { focus: "series" },
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            emphasis: { focus: "series" },
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            emphasis: { focus: "series" },
          },
          {
            type: "pie",
            id: "pie",
            radius: "30%",
            center: ["50%", "25%"],
            emphasis: {
              focus: "self",
            },
            label: {
              formatter: "{b}: {@2012} ({d}%)",
            },
            encode: {
              itemName: "部门1",
              value: "2012",
              tooltip: "2012",
            },
          },
        ],
      };
      myChart.on("updateAxisPointer", function (event) {
        const xAxisInfo = event.axesInfo[0];
        if (xAxisInfo) {
          const dimension = xAxisInfo.value + 1;
          myChart.setOption({
            series: {
              id: "pie",
              label: {
                formatter: "{b}: {@[" + dimension + "]} ({d}%)",
              },
              encode: {
                value: dimension,
                tooltip: dimension,
              },
            },
          });
        }
      });
      myChart.setOption(option);
    });

    option && myChart.setOption(option);
  },
};
</script>